package com.bootdo.cash.util;

import com.bootdo.common.redis.shiro.RedisManager;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @Desc
 * @date 2020/3/12
 *
 */
@Component
public class CashRedis {

    @Value("${spring.redis.host}")
    private String host;
    @Value("${spring.redis.password}")
    private String password;
    @Value("${spring.redis.port}")
    private int port;

    private RedisManager redisManager;

    public CashRedis(){
        redisManager = new RedisManager();
        redisManager.setHost(host);
        redisManager.setPort(port);
        redisManager.setPassword(password);
        redisManager.init();
    }

    /**
     * 添加缓存
     * @param key
     */
    public void set(String key, String value){
        redisManager.set(key, value);
    }

    public String get(String key){
        del(key);
        return redisManager.get(key);
    }

    /**
     * 删除缓存
     * @param key
     */
    public void del(String key){
        redisManager.del(key);
    }


}
